extends StaticBody2D

#这里当砖块被打倒时，判断它相邻的砖块是否应该消失，保证和原版的效果一致
func take_damage(_attack_val,bullet_dir:Vector2):
	if abs( bullet_dir.angle_to(Vector2.UP))<0.01||abs(bullet_dir.angle_to(Vector2.DOWN))<0.01:
		var brother_name= _get_brother_name(false)
		if has_node("../"+brother_name):
			get_node("../"+brother_name+"/CollisionShape2D").set_deferred("disabled",true)
			get_node("../"+brother_name).hide()
		self.hide()
		$CollisionShape2D.set_deferred("disabled",true)
	else:
		var brother_name= _get_brother_name(true)
		if has_node("../"+brother_name):
			get_node("../"+brother_name+"/CollisionShape2D").set_deferred("disabled",true)
			get_node("../"+brother_name).hide()
		self.hide()
		$CollisionShape2D.set_deferred("disabled",true)
	check_for_destroy()
func _get_brother_name(is_horizontal:bool)->String:
	if !is_horizontal:
		if self.name=="Brick1":
			return "Brick2"
		elif self.name=="Brick2":
			return "Brick1"
		elif self.name=="Brick3":
			return "Brick4"
		elif self.name=="Brick4":
			return "Brick3"
	else:
		if self.name=="Brick1":
			return "Brick3"
		elif self.name=="Brick3":
			return "Brick1"
		elif self.name=="Brick2":
			return "Brick4"
		elif self.name=="Brick4":
			return "Brick2"
	return "Error"

func check_for_destroy():
	if get_node("../Brick1").visible or get_node("../Brick2").visible or get_node("../Brick3").visible or get_node("../Brick4").visible:
		return
	get_node("../").queue_free()
		
